package ru.agiledev.aos.commons.dto;

/**
 * Extended query Class represent input query after performed analysis. It contains query transformed into
 * inner representation, distinctive OI, main objects of interest and addition for some type of objects.
 *
 * Created by Anton Kirillov
 * Date: 8/12/11
 */

import java.util.Iterator;
import java.util.List;

/**
 * DTO for extended query with meta-information (frontend class @see ru.agiledev.aos.frontend.shared.TransformationResults)
 */
public class SemanticQuery {
    Integer id;
    /**
     * Input query withou any transformations performed
     */
    String initialQuery;
    /**
     * Query represented as List of LightWord objects
     */
    List<LightWord> transformedQuery;
    /**
     * Distinctive object showing what kind of type and query represented
     */
    LightWord distinctiveObject;
    /**
     * Main objects of interest and additive object(show addition to query)
     */
    List<LightWord> firstObject, secondObject, additionalObject, dateObject;

    QType questionType;
    /**
     * Queries produced as a result of semantic extension
     */
    List<String> queries;

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        result.append("Initial query: "+initialQuery+"\n");
        result.append("Query type: "+questionType+"\n");

        if(distinctiveObject!=null){
            result.append("Distinctive object: "+distinctiveObject.getValue()+"\n");
        } else {
            result.append("Distinctive object: "+"не определен"+"\n");
        }


        if((firstObject!=null)&&(firstObject.size()>0)){
            StringBuilder lBuilder = new StringBuilder();
            for (Iterator<LightWord> iterator = firstObject.iterator(); iterator.hasNext();) {
                LightWord lightWord = iterator.next();
                lBuilder.append(lightWord.getValue());
                lBuilder.append(" ");
            }

            result.append("Object of interest 1: "+lBuilder+"\n");

        } else {
            result.append("Object of interest 1: не определен"+"\n");
        }

        if((secondObject!=null)&&(secondObject.size()>0)){
            StringBuilder lBuilder = new StringBuilder();
            for (Iterator<LightWord> iterator = secondObject.iterator(); iterator.hasNext();) {
                LightWord lightWord = iterator.next();
                lBuilder.append(lightWord.getValue());
                lBuilder.append(" ");
            }

            result.append("Object of interest 2: "+lBuilder+"\n");

        } else {
            result.append("Object of interest 2: не определен"+"\n");
        }

         if((additionalObject !=null)&&(additionalObject.size()>0)){
            StringBuilder lBuilder = new StringBuilder();
            for (Iterator<LightWord> iterator = additionalObject.iterator(); iterator.hasNext();) {
                LightWord lightWord = iterator.next();
                lBuilder.append(lightWord.getValue());
                lBuilder.append(" ");
            }
            result.append("Additional object: "+lBuilder+"\n");
        } else {
            result.append("Additional object: не определен"+"\n");
        }

        if((dateObject !=null)&&(dateObject.size()>0)){
            StringBuilder lBuilder = new StringBuilder();
            for (Iterator<LightWord> iterator = dateObject.iterator(); iterator.hasNext();) {
                LightWord lightWord = iterator.next();
                lBuilder.append(lightWord.getValue());
                lBuilder.append(" ");
            }
            result.append("Date object: "+lBuilder+"\n");
        } else {
            result.append("Date object: не определен"+"\n");
        }
        return result.toString();
    }

    /**
     * Method checks whether all fields of object is defined.
     * @return true if number of filled fields are enough for semantic extension
     */
    public boolean isSearchReady(){
        if((questionType!=null)&&(firstObject!=null)&&(firstObject.size()>0)){
            return true;
        }

        return false;
    }

    //getters and setters ------------------------------------------------------
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getInitialQuery() {
        return initialQuery;
    }

    public void setInitialQuery(String initialQuery) {
        this.initialQuery = initialQuery;
    }

    public List<LightWord> getTransformedQuery() {
        return transformedQuery;
    }

    public void setTransformedQuery(List<LightWord> transformedQuery) {
        this.transformedQuery = transformedQuery;
    }

    public LightWord getDistinctiveObject() {
        return distinctiveObject;
    }

    public void setDistinctiveObject(LightWord distinctiveObject) {
        this.distinctiveObject = distinctiveObject;
    }

    public List<LightWord> getFirstObject() {
        return firstObject;
    }

    public void setFirstObject(List<LightWord> firstObject) {
        this.firstObject = firstObject;
    }

    public List<LightWord> getSecondObject() {
        return secondObject;
    }

    public void setSecondObject(List<LightWord> secondObject) {
        this.secondObject = secondObject;
    }

    public QType getQuestionType() {
        return questionType;
    }

    public void setQuestionType(QType questionType) {
        this.questionType = questionType;
    }

    public List<String> getQueries() {
        return queries;
    }

    public void setQueries(List<String> queries) {
        this.queries = queries;
    }

    public List<LightWord> getAdditionalObject() {
        return additionalObject;
    }

    public void setAdditionalObject(List<LightWord> additionalObject) {
        this.additionalObject = additionalObject;
    }

    public List<LightWord> getDateObject() {
        return dateObject;
    }

    public void setDateObject(List<LightWord> dateObject) {
        this.dateObject = dateObject;
    }
}
